package com.psp.web.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.web.model.OrderBean;
import com.psp.web.persist.dao.OrderDao;

@Repository
public class OrderImpl extends BaseImpl implements OrderDao {

	final String NAME_SPACE = NAME_SPACE_HEADER + ".OrderMapper";

	@Override
	public int insert(OrderBean bean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", bean);
	}

	@Override
	public OrderBean selectById(String oid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectById", oid);
	}

	@Override
	public int selectCount(String uid, String orderNo, int[] state) {
		Map<String, Object> where = new HashMap<>();
		where.put("uid", uid);
		where.put("orderNo", orderNo);
		where.put("state", state);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public List<OrderBean> selectList(Integer page, Integer pageSize, String uid, String orderNo, int[] state) {
		Map<String, Object> where = new HashMap<>();
		where.put("uid", uid);
		where.put("orderNo", orderNo);
		where.put("state", state);
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int updateOrderState(OrderBean order, int state) {
		Map<String, Object> where = new HashMap<>();
		where.put("oid", order.getOid());
		where.put("state", state);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateOrderState", where);
		
	}

	@Override
	public OrderBean selectByOrderNo(String orderNo) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectByOrderNo", orderNo);
	}

}
